package demo.ws;

import java.util.Calendar;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.xml.bind.DatatypeConverter;

@Path("/hello")
public class HelloWorld {

    @GET
    @Path("/echo/{input}")
    @Produces("text/plain")
    public String ping(@PathParam("input") String input) {
        return input;
    }

    @GET
    @Produces("application/json")
    @Path("/jsonBean")
    public Response getJson() {
        JsonBean entity = new JsonBean();
        Calendar time = DatatypeConverter.parseDateTime("2012-09-11T19:48:00.000+08:00");
        entity.setDate(time.getTime());
        return Response.ok().entity(entity).build(); // 2012-09-11T19:48:00+08:00
    }

    @POST
    @Produces("application/json")
    @Consumes("application/json")
    @Path("/jsonBean")
    public Response modifyJson(JsonBean input) {
        input.setVal2(input.getVal1());
        return Response.ok().entity(input).build();
    }
}
